package sprites;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;

import panels.ActorPanel;

public class ActorSprite extends RectangleSprite {
	
	public static final Color defaultColor = Color.blue;
	
	public enum ActorSize {
		tiny,
		small,
		medium,
		large,
		huge,
		gargantuan,
		colossal
	}
	
	private static Dimension getDimension(ActorSize A) {
		if (A == ActorSize.large) {
			return new Dimension(2,2);
		} else if (A == ActorSize.huge) {
			return new Dimension(3,3);
		} else if (A == ActorSize.gargantuan) {
			return new Dimension(4,4);
		} else if (A == ActorSize.colossal) {
			return new Dimension(5,5);
		} else {
			return new Dimension(1,1);
		}
	}
	
	private ActorSize 	size = ActorSize.medium;
	private ActorPanel	panel = null;
	
	public ActorSprite(Point P, ActorSize S, ActorPanel A) {
		super(P, getDimension(S));
		setPanel(A);
		setSize(S);
		setColor(defaultColor);
	}

	public ActorSize getSize() {
		return size;
	}

	public void setSize(ActorSize size) {
		this.size = size;
		this.setBounds(getDimension(size));
	}
	
	@Override 
	public void paintPoint(Graphics G, Rectangle R) {
		Color	oldColor = G.getColor();
		Rectangle	R2;
		
		G.setColor(getColor());
		if (this.getSize() == ActorSize.tiny) {
			R2 = new Rectangle(R.x + R.width/4, R.y+R.width/4, R.width/2, R.height/2);
		} else if (this.getSize() == ActorSize.small) {
			R2 = new Rectangle(R.x + R.width/8, R.y+R.width/8, R.width*3/4, R.height*3/4);
		} else {
			R2 = new Rectangle(R.x, R.y, R.width*this.getBounds().width, R.height*this.getBounds().height);
		}
		G.fillOval(R2.x,  R2.y,  R2.width, R2.height);
		
		G.setColor(oldColor);
		G.drawArc(R2.x, R2.y,  R2.width, R2.height, 0, 360);
		
		if (this.panel != null) {
			G.drawString(panel.getActorName().getText(), R.x, R.y-5);
		} else {
			G.drawString(getName(), R.x, R.y-5);
		}
	}

	public ActorPanel getPanel() {
		return panel;
	}

	public void setPanel(ActorPanel panel) {
		if (this.panel != null && this.panel.getSprite() != this) {
			this.panel.setSprite(null);
		}
		this.panel = panel;
		if (this.panel != null && this.panel.getSprite() != this) {
			this.panel.setSprite(this);
		}
	}
	
	public String getName() {
		if (this.panel != null) {
			return this.panel.getName();
		} else {
			return "No Panel";
		}
	}
	
	public void setName(String N) {
		if (N==null) N = "";
		super.setName(N);
		if (panel != null && panel.getName() != null && !panel.getName().equals(N)) {
			panel.setName(N);
		}
	}
	
	public Color getColor() {
		if (this.getPanel() != null) {
			return this.getPanel().getHealthBar().getForeground();
		} else {
			return super.getColor();
		}
	}
}
